﻿@model List<RiderShop.Mobile.ServiceEntity.MyAccount.UserShipingAddressExtend>

@section header
{
    <style type="text/css">
        body, html {
            width: 100%;
            height: 100%;
            margin: 0;
            font-family: \5FAE\8F6F\96C5\9ED1, "Microsoft YaHei", "Hiragino Sans GB", "WenQuanYi Micro Hei", sans-serif;
        }

        div ~ #allmap {
            height: 100%;
        }

        #allmap {
            width: 100%;
            height: 100%;
        }

        p {
            margin-left: 5px;
            font-size: 14px;
        }

        header, footer {
            display: none;
        }
    </style>}

@section title {
    自提点地图
}
<div id="allmap"></div>

@section footer
{
    <script type="text/javascript" src="http://api.map.baidu.com/api?type=quick&v=1.0&ak=DAbdc3f5b3659bd307ccfd675e4a0730"></script>

    @Html.Raw("<script src='/Themes/RongJi/Style/base/js/map_ex.js'></script>")

    <script type="text/javascript">
        document.getElementById("allmap").parentNode.style.height = '100%';
        //百度地图API功能
        var map = new BMap.Map("allmap"); //new Map
        var point = new BMap.Point(108.953098, 34.277561); //Location, （经度, 纬度）
        map.centerAndZoom(point, 13);//show Map
        var zoomControl = new BMap.ZoomControl();
        map.addControl(zoomControl);//添加缩放控件

        @{
            var sb = new System.Text.StringBuilder();
            foreach(var add in Model)
            {

                sb.AppendLine(string.Format("[{0}, {1}, '{2}', '地址：{3}', \"<input onclick=changeZiTiDian('{4}',{5}); type='button' value='选择此地点' style='color: black;' />\",'{6}'],"
                    ,add.Longitude,
                    add.Latitude,
                    add.ShipTo,
                    add.RegionAddress+add.Address,
                    add.ShipTo,
                    add.ShippingId,
                    add.Zipcode));
            }
        }


        //所有的自提点
        var data_info = [
            @Html.Raw(sb.ToString())

                         //[109.012064, 34.246733, "经二路店", "地址：陕西省西安市新城区公园南路负10号", "<input onclick=changeZiTiDian('西安经二路店',10); type='button' value='选择此地点' style='color: black;' />", "02"],
                         //[109.012841, 34.26198, "康乐路店", "地址：陕西省西安市新城区韩森路61号", "<input onclick=changeZiTiDian('西安康乐路店',11); type='button' value='选择此地点' style='color: black;' />", "02"],
                         //[108.923889, 34.230662, "科技路店", "地址：陕西省西安市雁塔区太白南路263号", "<input onclick=changeZiTiDian('西安科技路店',12); type='button' value='选择此地点' style='color: black;' />", "02"],
                         //[108.942046, 34.21005, "明德门店", "地址：陕西省西安市雁塔区明德门小区千禧阁厦一层", "<input onclick=changeZiTiDian('西安明德门店',13); type='button' value='选择此地点' style='color: black;' />", "02"],
                         //[108.984599, 34.241085, "南二环店", "地址：陕西省西安市碑林区南二环东段236号1单元1层 1号", "<input onclick=changeZiTiDian('西安南二环店',14); type='button' value='选择此地点' style='color: black;' />", "02"],
                         //[108.84802, 34.304335, "三桥店店", "地址：陕西省西安市未央区三桥建章路车辆厂十字", "<input onclick=changeZiTiDian('西安三桥店店',15); type='button' value='选择此地点' style='color: black;' />", "02"],
                         //[108.975548, 34.278045, "尚爱路店", "地址：陕西省西安市新城区尚爱路55号青海大型门店厦一层", "<input onclick=changeZiTiDian('西安尚爱路店',16); type='button' value='选择此地点' style='color: black;' />", "02"],
                         //[108.97513, 34.280998, "尚勤路店", "地址：陕西省西安市新城区尚勤路东八路和东七路之间", "<input onclick=changeZiTiDian('西安尚勤路店',17); type='button' value='选择此地点' style='color: black;' />", "02"],
                         //[108.94579, 34.334716, "文景路店", "地址：陕西省西安市未央区凤城二路与文景路交界东南角海璟国际", "<input onclick=changeZiTiDian('西安文景路店',18); type='button' value='选择此地点' style='color: black;' />", "02"],
                         //[108.960661, 34.253424, "文艺路店", "地址：陕西省西安市碑林区文艺北路133号", "<input onclick=changeZiTiDian('西安文艺路店',19); type='button' value='选择此地点' style='color: black;' />", "02"],
                         //[108.994446, 34.26864, "兴庆路店", "地址：陕西省西安市碑林区兴庆路70号", "<input onclick=changeZiTiDian('西安兴庆路店',20); type='button' value='选择此地点'/ >", "02"],
                         //[109.024039, 34.26823, "幸福二店", "地址：陕西省西安市新城区幸福中路123号幸福嘉苑小区", "<input onclick=changeZiTiDian('西安幸福二店',21); type='button' value='选择此地点' style='color: black;' />", "02"],
                         //[109.024039, 34.26823, "幸福一店", "地址：陕西省西安市新城区幸福中路123号幸福嘉苑小区", "<input onclick=changeZiTiDian('西安幸福一店',22); type='button' value='选择此地点' style='color: black;' />", "02"],
                         //[108.972193, 34.354217, "徐家湾店", "地址：陕西省西安市未央区渭滨路62号", "<input onclick=changeZiTiDian('西安徐家湾店',23); type='button' value='选择此地点' style='color: black;' />", "02"],
                         //[108.972134, 34.264143, "玄风桥店", "地址：陕西省西安市碑林区建国路玄风桥4号阳光里10114室", "<input onclick=changeZiTiDian('西安玄风桥店',24); type='button' value='选择此地点' style='color: black;' />", "02"],
                         //[108.942514, 34.247882, "友谊路店", "地址：陕西省西安市碑林区红缨路1号", "<input  name='address' onclick=changeZiTiDian('西安友谊路店',25); type='button' value='选择此地点' style='color: black;' />", "02"],
        ];

        //信息窗口设置
        var opts = {
            width: 250,           // 信息窗口宽度
            height: 90,            // 信息窗口高度
            //title : "信息窗口" , // 信息窗口标题
            enableMessage: false    //设置允许信息窗发送短息
        };

        //添加标注到地图
        for (var i = 0; i < data_info.length; i++) {
            //var marker = new BMap.Marker(new BMap.Point(data_info[i][0], data_info[i][1]));  //创建标注
            //var content = data_info[i][2] + "<br/>" + data_info[i][3] + data_info[i][4];
            //map.addOverlay(marker);//将标注添加到地图中
            //addClickHandler(content, marker);

            var jsonData = {
                ID: i,
                SELLSTATE: data_info[i][5],
                lng: data_info[i][0],
                lat: data_info[i][1],
                content: data_info[i][2] + "<br/>" + data_info[i][3] + "<br/>" + data_info[i][4]
            };
            var point = new BMap.Point(data_info[i][0], data_info[i][1]);
            var myCompOverlay = new ComplexCustomOverlay(point, data_info[i][2], data_info[i][2] + "-" + data_info[i][3], jsonData, "zyproject");
            map.addOverlay(myCompOverlay);

        }

        //打开信息窗口
        function addClickHandler(content, marker) {
            marker.addEventListener("click", function (e) {
                openInfo(content, e)
            });
        }

        //选择自提点跳转
        function changeZiTiDian(zitidian, index) {
            window.location.href = '/Purchase/CheckOut?zitidian=' + zitidian + "&index=" + index;
        }

        //打开窗口
        function openInfo(content, e) {
            var p = e.target;
            var point = new BMap.Point(p.getPosition().lng, p.getPosition().lat);
            var infoWindow = new BMap.InfoWindow(content, opts);  //创建信息窗口对象
            map.openInfoWindow(infoWindow, point); //开启信息窗口
        }

        wx.ready(function () {
            wx.getLocation({
                success: function (res) {
                    var latitude = res.latitude; // 纬度，浮点数，范围为90 ~ -90
                    var longitude = res.longitude; // 经度，浮点数，范围为180 ~ -180。
                    var speed = res.speed; // 速度，以米/每秒计
                    var accuracy = res.accuracy; // 位置精度
                    //alert(latitude);

                    var point = new BMap.Point(res.longitude, res.latitude); //Location, （经度, 纬度）
                    map.centerAndZoom(point, 13);//show Map
                },
                fail: function (res) {
                },
                cancel: function (res) {
                }
            });
        });
    </script>
}